package com.itheima.tlias08_14.config;

import com.itheima.tlias08_14.filter.LoginInterceptor;
import jakarta.annotation.Resource;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * spring 配置类 ：用于配置拦截器，跨域配置等
 *
 * @Configuration 标识当前类为配置类, 其中包含了@Component注解
 * 过滤器（Filter）与拦截器（Interceptor）的区别：
 * 相同点：执行都在controller（servLet）之前
 * 不同点：技术提供方：过滤器->servLet拦截器->spring
 * 执行顺序：先执行过滤器后执行拦截器
 * 拦截粒度：过滤器过滤粒度粗->编码转换，时间格式转换
 * 拦截器拦截粒度细>登录认证，接口日志记录*/
@Configuration
//public class WebMvcConfig extends WebMvcConfigurationSupport {
public class WebMvcConfig implements WebMvcConfigurer {

    @Resource
    LoginInterceptor loginInterceptor;
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        InterceptorRegistration ir = registry.addInterceptor(loginInterceptor);
        ir.addPathPatterns("/**").excludePathPatterns("/login","/readConfig");
    }
}
